1 == True: pytestの例
code: pytest_example.py
from unittest.mock import patch
def function(is_awesome):
print("hoge")
def test_1_true():
assert 1 == True # 1を2に変えたら成り立たない
assert 2
def test_0_false():
assert 0 == False
@patch("pytest_example.function")
def test_patch_1_true(function):
function(is_awesome=True)
function.assert_called_once_with(is_awesome=1) # 1を2に変えたら成り立たない
@patch("pytest_example.function")
def test_patch_0_false(function):
function(is_awesome=False)
function.assert_called_once_with(is_awesome=0)
code:shell
$ pytest pytest_example.py -s
============================= test session starts ==============================
platform darwin -- Python 3.9.4, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /...
collected 4 items
pytest_example.py ....
============================== 4 passed in 0.04s ===============================